//
//  WSDataReportDataSourceManager.m
//  microvision
//
//  Created by zhenjingxiong on 2021/3/12.
//  Copyright © 2021 tencent. All rights reserved.
//

#import "WSDataReportDataSourceManager.h"
#import "WSDataReportFilterManager.h"

static NSInteger  const gReportDataSourceMaxCount  = 1000;

@implementation WSDataReportDataSourceManager

+ (instancetype)instance {
    static WSDataReportDataSourceManager *instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[WSDataReportDataSourceManager alloc] init];
        instance.dataSourceMaxCount = gReportDataSourceMaxCount;
    });
    return instance;
}


- (NSMutableArray *)dataReportdataSource {
    if (!_dataReportdataSource) {
        _dataReportdataSource = [NSMutableArray array];
    }
    return _dataReportdataSource;
}

- (void)addReportData:(NSDictionary *)reportData {
    [self.dataReportdataSource insertObject:reportData atIndex:0];
    // 超出了最大存储数量限制, 把最旧的记录删除掉
    if (self.dataReportdataSource.count > self.dataSourceMaxCount) {
        [self.dataReportdataSource removeLastObject];
    }
    [[WSDataReportFilterManager instance] updateFilterDataSource];
}

- (void)removeCurrentAllReportData {
    [self.dataReportdataSource removeAllObjects];
    [[WSDataReportFilterManager instance] updateFilterDataSource];
}

@end
